/*
 * INSTRUCTION: This is a command line application. So please execute this template with the following arguments: arg[0]
 * = username arg[1] = password
 */

/**
 * @author (Your Name Here)
 */

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import com.google.gdata.client.photos.PicasawebService;
import com.google.gdata.data.photos.GphotoEntry;
import com.google.gdata.data.photos.UserFeed;
import com.google.gdata.util.AuthenticationException;
import com.google.gdata.util.ServiceException;

/**
 * This is a test template
 */

public class PicasaWebAlbums {

    @SuppressWarnings("unchecked")
    public static void main(String[] args) {
        args = new String[] { "julienboz", "161080" };

        try {
            // Create a new Picasa Web Albums service
            final PicasawebService myService = new PicasawebService("My Application");
            myService.setUserCredentials(args[0], args[1]);

            // Get a list of all entries
            final URL metafeedUrl = new URL("http://picasaweb.google.com/data/feed/api/user/" + args[0] + "?kind=album");
            System.out.println("Getting Picasa Web Albums entries...\n");
            final UserFeed resultFeed = myService.getFeed(metafeedUrl, UserFeed.class);
            final List<GphotoEntry> entries = resultFeed.getEntries();
            for (int i = 0; i < entries.size(); i++) {
                final GphotoEntry entry = entries.get(i);
                System.out.println("\t" + entry.getTitle().getPlainText());
            }
            System.out.println("\nTotal Entries: " + entries.size());
        } catch (final AuthenticationException e) {
            e.printStackTrace();
        } catch (final MalformedURLException e) {
            e.printStackTrace();
        } catch (final ServiceException e) {
            e.printStackTrace();
        } catch (final IOException e) {
            e.printStackTrace();
        }
    }
}
